package com.comp490.sprite;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;

import com.comp490.shooter.GameView;

public class ExplosionSprite
{
	public static final int EXPLOSION_ONE 		= 0;
	public static final int EXPLOSION_TWO 		= 1;
	public static final int EXPLOSION_THREE 	= 2;
	public static final int EXPLOSION_FOUR 		= 3;
	public static final int EXPLOSION_FIVE 		= 4;
	public static final int EXPLOSION_SIX 		= 5;
	public static final int EXPLOSION_SEVEN 	= 6;
	public static final int EXPLOSION_EIGHT 	= 7;
	
    private int fCount;
    private int spriteLeft;
    private int spriteTop;
    private int bitmapHeight;
    private int bitmapWidth;
    private Bitmap mExplosionsPic;
    private Rect src;
    private Rect dst;

    public ExplosionSprite(GameView gameView)
    {
        mExplosionsPic = BitmapResource.EXPLOSION;
        bitmapHeight = mExplosionsPic.getHeight() / 8;
        bitmapWidth = mExplosionsPic.getWidth() / 16;
        fCount = spriteLeft = 0;
        spriteTop = 0;
        src = new Rect();
        dst = new Rect();
    }

    public boolean draw(Canvas canvas, float xLocation, float yLocation, int explosionType)
    {
    	spriteTop = explosionType * bitmapHeight;

        
		src.set(spriteLeft, spriteTop + bitmapHeight, spriteLeft + bitmapWidth,
                spriteTop + 2 * bitmapHeight);
        dst.set((int) xLocation, (int) yLocation, (int) xLocation
                + bitmapWidth, (int) yLocation + bitmapHeight);

        canvas.drawBitmap(mExplosionsPic, src, dst, null);
        if(fCount++ % 5 == 0)
            spriteLeft += bitmapWidth;

        if(spriteLeft > mExplosionsPic.getWidth())
        {
            fCount = 0;
            spriteLeft = 0;
            return false;
        }
        return true;
    }
}